import Vue from 'vue'
import Router from 'vue-router'

Vue.use(Router)

/* Layout */
import Layout from '@/layout'

export const constantRoutes = [
  {
    path: '/login',
    component: () => import('@/views/login/index'),
    hidden: true
  },

  {
    path: '/404',
    component: () => import('@/views/404'),
    hidden: true
  },

  {
    path: '/',
    component: Layout,
    redirect: '/home',
    children: [{
      path: 'home',
      name: 'Home',
      component: () => import('@/views/home/index'),
      meta: { title: '首页', icon: 'dashboard' }
    }]
  },

  {
    path: '/stock',
    component: Layout,
    redirect: '/stock/in',
    name: 'Stock',
    meta: {
      title: '库存管理',
      icon: 'dashboard'
    },
    children: [
      {
        path: 'in',
        component: () => import('@/views/stock/in/index'),
        name: 'In',
        meta: { title: '入库管理' },
        children: [
          {
            path: 'purchase',
            component: () => import('@/views/stock/in/purchase.vue'),
            name: 'Purchase1',
            meta: { title: '采购入库' }
          },
          {
            path: 'rubric',
            component: () => import('@/views/stock/in/rubric.vue'),
            name: 'Rubric1',
            meta: { title: '采购退货出库(红入)' }
          },
          {
            path: 'check',
            component: () => import('@/views/stock/in/check.vue'),
            name: 'Check1',
            meta: { title: '盘盈入库' }
          },
          {
            path: 'swell',
            component: () => import('@/views/stock/in/swell.vue'),
            name: 'Swell',
            meta: { title: '涨吨入库' }
          },
          {
            path: 'other',
            component: () => import('@/views/stock/in/other.vue'),
            name: 'Other1',
            meta: { title: '其他入库' }
          }
        ]
      },
      {
        path: 'out',
        component: () => import('@/views/stock/out/index'),
        name: 'Out',
        meta: { title: '出库管理' },
        children: [
          {
            path: 'sale',
            component: () => import('@/views/stock/out/sale.vue'),
            name: 'Sale2',
            meta: { title: '销售出库' }
          },
          {
            path: 'rubric',
            component: () => import('@/views/stock/out/rubric'),
            name: 'Rubric2',
            meta: { title: '销售退货入库(红出)' },
          },
          {
            path: 'check',
            component: () => import('@/views/stock/out/check'),
            name: 'Check2',
            meta: { title: '盘亏出库' }
          },
          {
            path: 'other',
            component: () => import('@/views/stock/out/other'),
            name: 'Other2',
            meta: { title: '其他出库' }
          },
        ]
      },
      {
        path: 'other',
        component: () => import('@/views/stock/other/index'),
        name: 'Other3',
        meta: { title: '其他管理' },
        children: [
          {
            path: 'move',
            component: () => import('@/views/stock/other/move'),
            name: 'Move',
            meta: { title: '库存挑拨' }
          },
          {
            path: 'cost',
            component: () => import('@/views/stock/other/cost'),
            name: 'Cost',
            meta: { title: '成本调整' },
          },
          {
            path: 'check',
            component: () => import('@/views/stock/other/check'),
            name: 'Check3',
            meta: { title: '库存盘点' }
          },
        ]
      },
      {
        path: 'inventory',
        component: () => import('@/views/stock/inventory/index'),
        name: 'Inventory',
        meta: { title: '即时库存' },
        children: [
          {
            path: 'm',
            component: () => import('@/views/stock/inventory/m'),
            name: 'M',
            meta: { title: '物料库存' }
          },
          {
            path: 'mb',
            component: () => import('@/views/stock/inventory/mb'),
            name: 'Mb',
            meta: { title: '物料批次库存' },
          },
          {
            path: 'wm',
            component: () => import('@/views/stock/inventory/wm'),
            name: 'Wm',
            meta: { title: '仓库物料库存' }
          },
          {
            path: 'wmb',
            component: () => import('@/views/stock/inventory/wmb'),
            name: 'Wmb',
            meta: { title: '详细库存' }
          },
        ]
      },
      {
        path: 'statistics',
        component: () => import('@/views/stock/statistics/index'),
        name: 'Statistics1',
        meta: { title: '出入库统计' },
        children: [
          {
            path: 'month',
            component: () => import('@/views/stock/statistics/month'),
            name: 'Month1',
            meta: { title: '出入库月汇总' }
          },
          {
            path: 'day',
            component: () => import('@/views/stock/statistics/day'),
            name: 'Day',
            meta: { title: '出入库日汇总' },
          },
          {
            path: 'detail',
            component: () => import('@/views/stock/statistics/detail'),
            name: 'Detail1',
            meta: { title: '出入库明细' }
          },
        ]
      }
    ]
  },

  {
    path: '/rec',
    component: Layout,
    redirect: '/rec/receivable',
    name: 'Rec',
    meta: {
      title: '应收与收款',
      icon: 'nested'
    },
    children: [
      {
        path: 'sale',
        component: () => import('@/views/rec/receivable/index'),
        name: 'Sale3',
        meta: { title: '应收管理' },
        children: [
          {
            path: 'sale',
            component: () => import('@/views/rec/receivable/sale'),
            name: 'Sale4',
            meta: { title: '销售应收' }
          },
          {
            path: 'other',
            component: () => import('@/views/rec/receivable/other'),
            name: 'Other4',
            meta: { title: '其他应收' },
          },
          {
            path: 'check',
            component: () => import('@/views/rec/receivable/check'),
            name: 'Check4',
            meta: { title: '应收核销' }
          },
        ]
      },
      {
        path: 'prereceipt',
        component: () => import('@/views/rec/prereceipt/index'),
        name: 'Prereceipt',
        meta: { title: '预收管理' },
        children: [
          {
            path: 'sale',
            component: () => import('@/views/rec/prereceipt/sale'),
            name: 'Sale5',
            meta: { title: '销售预收' }
          },
          {
            path: 'other',
            component: () => import('@/views/rec/prereceipt/other'),
            name: 'Other5',
            meta: { title: '其他预收' },
          },
        ]
      },
      {
        path: 'receipt',
        component: () => import('@/views/rec/receipt/index'),
        name: 'Receipt',
        meta: { title: '收款管理' },
        children: [
          {
            path: 'sale',
            component: () => import('@/views/rec/receipt/sale'),
            name: 'Sale6',
            meta: { title: '销售收款' }
          },
          {
            path: 'salerequest',
            component: () => import('@/views/rec/receipt/salerequest'),
            name: 'Salerequest',
            meta: { title: '销售退货退款申请(红收)' },
          },
          {
            path: 'salebackhave',
            component: () => import('@/views/rec/receipt/salebackhave'),
            name: 'Salebackhave',
            meta: { title: '销售退货退款(有申请)' }
          },
          {
            path: 'salebacknone',
            component: () => import('@/views/rec/receipt/salebacknone'),
            name: 'Salebacknone',
            meta: { title: '销售退货退款(无申请)' }
          },
          {
            path: 'other',
            component: () => import('@/views/rec/receipt/other'),
            name: 'Other6',
            meta: { title: '其他收款' }
          },
        ]
      },
      {
        path: 'statistics',
        component: () => import('@/views/rec/statistics/index'),
        name: 'Statistics2',
        meta: { title: '应收统计' },
        children: [
          {
            path: 'check',
            component: () => import('@/views/rec/statistics/check'),
            name: 'Check5',
            meta: { title: '应收对账' }
          },
          {
            path: 'detail',
            component: () => import('@/views/rec/statistics/detail'),
            name: 'Detail2',
            meta: { title: '应收明细' },
          },
          {
            path: 'month',
            component: () => import('@/views/rec/statistics/month'),
            name: 'Month2',
            meta: { title: '应收月汇总' }
          },
          {
            path: 'bal',
            component: () => import('@/views/rec/statistics/bal'),
            name: 'Bal',
            meta: { title: '应收即时余额' }
          },
        ]
      }
    ]
  },

  {
    path: '/pay',
    component: Layout,
    redirect: '/pay/payable',
    name: 'Pay',
    meta: {
      title: '应付与付款',
      icon: 'nested'
    },
    children: [
      {
        path: 'payable',
        component: () => import('@/views/pay/payable/index'),
        name: 'Payable',
        meta: { title: '应付管理' },
        children: [
          {
            path: 'purchase',
            component: () => import('@/views/pay/payable/purchase'),
            name: 'Purchase2',
            meta: { title: '采购应付' }
          },
          {
            path: 'other',
            component: () => import('@/views/pay/payable/other'),
            name: 'Other7',
            meta: { title: '其他应付' },
          },
          {
            path: 'check',
            component: () => import('@/views/pay/payable/check'),
            name: 'Check6',
            meta: { title: '应付核销' }
          },
        ]
      },
      {
        path: 'prepayment',
        component: () => import('@/views/pay/prepayment/index'),
        name: 'Prepayment',
        meta: { title: '预付管理' },
        children: [
          {
            path: 'paywithreq',
            component: () => import('@/views/pay/prepayment/paywithreq'),
            name: 'Paywithreq1',
            meta: { title: '采购预付(有申请)' }
          },
          {
            path: 'paywithoutreq',
            component: () => import('@/views/pay/prepayment/paywithoutreq'),
            name: 'Paywithoutreq2',
            meta: { title: '采购预付(无申请)' },
          },
          {
            path: 'other',
            component: () => import('@/views/pay/prepayment/other'),
            name: 'Other8',
            meta: { title: '其他预付申请' },
          },
          {
            path: 'otherwithreq',
            component: () => import('@/views/pay/prepayment/otherwithreq'),
            name: 'Otherwithreq1',
            meta: { title: '其他预付(有申请)' },
          },
          {
            path: 'otherwithoutreq',
            component: () => import('@/views/pay/prepayment/otherwithoutreq'),
            name: 'Otherwithoutreq1',
            meta: { title: '其他预付(无申请)' },
          },
        ]
      },
      {
        path: 'payment',
        component: () => import('@/views/pay/payment/index'),
        name: 'Payment',
        meta: { title: '付款管理' },
        children: [
          {
            path: 'paywithreq',
            component: () => import('@/views/pay/payment/paywithreq'),
            name: 'Paywithreq2',
            meta: { title: '采购付款(有申请)' }
          },
          {
            path: 'paywithoutreq',
            component: () => import('@/views/pay/payment/paywithoutreq'),
            name: 'Paywithoutreq1',
            meta: { title: '采购付款(无申请)' },
          },
          {
            path: 'redpay',
            component: () => import('@/views/pay/payment/redpay'),
            name: 'Redpay',
            meta: { title: '采购退货退款(红付)' },
          },
          {
            path: 'other',
            component: () => import('@/views/pay/payment/other'),
            name: 'Other9',
            meta: { title: '其他付款申请' },
          },
          {
            path: 'otherwithreq',
            component: () => import('@/views/pay/payment/otherwithreq'),
            name: 'Otherwithreq2',
            meta: { title: '其他付款(有申请)' },
          },
          {
            path: 'otherwithoutreq',
            component: () => import('@/views/pay/payment/otherwithoutreq'),
            name: 'Otherwithoutreq2',
            meta: { title: '其他付款(无申请)' },
          },
        ]
      },
      {
        path: 'statisics',
        component: () => import('@/views/pay/statisics/index'),
        name: 'Statisics',
        meta: { title: '应付统计' },
        children: [
          {
            path: 'detail',
            component: () => import('@/views/pay/statisics/detail'),
            name: 'Detail3',
            meta: { title: '应付明细' }
          },
          {
            path: 'check',
            component: () => import('@/views/pay/statisics/check'),
            name: 'Check7',
            meta: { title: '应付对账' },
          },
          {
            path: 'month',
            component: () => import('@/views/pay/statisics/month'),
            name: 'Month3',
            meta: { title: '应付月汇总' }
          },
          {
            path: 'money',
            component: () => import('@/views/pay/statisics/money'),
            name: 'Money',
            meta: { title: '应付即时余额' }
          },
        ]
      }
    ]
  },


  {
    path: '/invoice',
    component: Layout,
    redirect: '/invoice/sale',
    name: 'Invoice',
    meta: { title: '发票登记', icon: 'el-icon-s-help' },
    children: [
      {
        path: 'sale',
        name: 'Sale1',
        component: () => import('@/views/invoice/sale'),
        meta: { title: '销售发票', icon: 'table' }
      },
      {
        path: 'purchaseRed',
        name: 'PurchaseRed',
        component: () => import('@/views/invoice/purchaseRed'),
        meta: { title: '销售发票(红冲)', icon: 'tree' }
      },
      {
        path: 'saleOut',
        name: 'SaleOut',
        component: () => import('@/views/invoice/saleOut'),
        meta: { title: '销售发票(退货)', icon: 'tree' }
      },
      {
        path: 'purchase',
        name: 'Purchase3',
        component: () => import('@/views/invoice/purchase'),
        meta: { title: '采购发票', icon: 'purchase' }
      },
      {
        path: 'saleRed',
        name: 'SaleRed',
        component: () => import('@/views/invoice/saleRed'),
        meta: { title: '销售发票(红冲)', icon: 'tree' }
      },
      {
        path: 'purchaseOut',
        name: 'PurchaseOut',
        component: () => import('@/views/invoice/purchaseOut'),
        meta: { title: '采购发票(退货)', icon: 'tree' }
      },
    ]
  },

  {
    path: '/base',
    component: Layout,
    redirect: '/base',
    name: 'Base',
    meta: { title: '基础资料', icon: 'el-icon-s-help' },
    children: [
      {
        path: '/customer',
        name: 'Customer',
        component: () => import('@/views/base/customer'),
        meta: { title: '客户', icon: 'table' }
      },
      {
        path: '/supplier',
        name: 'Supplier',
        component: () => import('@/views/base/supplier'),
        meta: { title: '供应商', icon: 'tree' }
      },
      {
        path: '/warehouse',
        name: 'Warehouse',
        component: () => import('@/views/base/warehouse'),
        meta: { title: '仓库', icon: 'tree' }
      },
      {
        path: '/materialCategory',
        name: 'MaterialCategory',
        component: () => import('@/views/base/materialCategory'),
        meta: { title: '物料分类', icon: 'tree' }
      },
      {
        path: '/material',
        name: 'Material',
        component: () => import('@/views/base/material'),
        meta: { title: '物料', icon: 'tree' }
      },
      {
        path: '/unit',
        name: 'Unit',
        component: () => import('@/views/base/unit'),
        meta: { title: '计量单位', icon: 'tree' }
      },
      {
        path: '/currency',
        name: 'Currency',
        component: () => import('@/views/base/currency'),
        meta: { title: '币种', icon: 'tree' }
      },
      {
        path: '/bankAccount',
        name: 'BankAccount',
        component: () => import('@/views/base/bankAccount'),
        meta: { title: '银行账户', icon: 'tree' }
      }
    ]
  },

  {
    path: '/monitor',
    component: Layout,
    redirect: '/monitor/menu1',
    name: 'Monitor',
    meta: {
      title: '业务监控',
      icon: 'nested'
    },
    children: [
      {
        path: 'closeAccounts',
        component: () => import('@/views/monitor/closeAccounts'),
        name: 'CloseAccounts',
        meta: { title: '月度结账' },
      },
      {
        path: 'billOptions',
        component: () => import('@/views/monitor/billOptions'),
        name: 'BillOptions',
        meta: { title: '单据选项' },
      },

    ]
  },

  {
    path: '/isystem',
    component: Layout,
    redirect: '/isystem/menu1',
    name: 'Isystem',
    meta: {
      title: '系统监控',
      icon: 'nested'
    },
    children: [
      {
        path: 'gatewayroute',
        component: () => import('@/views/isystem/gatewayroute'),
        name: 'Gatewayroute',
        meta: { title: '路由网关' },
      },
      {
        path: 'online',
        component: () => import('@/views/isystem/online'),
        name: 'Online',
        meta: { title: '在线用户' },
      },
      {
        path: 'QuartzJobList',
        component: () => import('@/views/isystem/QuartzJobList'),
        name: 'QuartzJobList',
        meta: { title: '定时任务' },
      },
      {
        path: 'log',
        component: () => import('@/views/isystem/log'),
        name: 'Log',
        meta: { title: '日志管理' },
      },
      {
        path: 'dataLog-list',
        component: () => import('@/views/isystem/dataLog-list'),
        name: 'DataLog-list',
        meta: { title: '数据日志' },
      },
      {
        path: 'perform',
        component: () => import('@/views/isystem/perform/index'),
        name: 'Perform',
        meta: { title: '性能监控'},
        children: [
          {
            path: 'info',
            component: () => import('@/views/isystem/perform/info'),
            name: 'Info',
            meta: { title: 'Redis监控'},
          },
          {
            path: 'SystemInfo',
            component: () => import('@/views/isystem/perform/SystemInfo'),
            name: 'SystemInfo',
            meta: { title: '服务器信息'},
          },
          {
            path: 'HttpTrace',
            component: () => import('@/views/isystem/perform/HttpTrace'),
            name: 'HttpTrace',
            meta: { title: '请求追踪'},
          },
          {
            path: 'TomcatInfo',
            component: () => import('@/views/isystem/perform/TomcatInfo'),
            name: 'TomcatInfo',
            meta: { title: 'Tomcat信息'},
          },
          {
            path: 'JvmInfo',
            component: () => import('@/views/isystem/perform/JvmInfo'),
            name: 'JvmInfo',
            meta: { title: 'JVM信息'},
          },
          {
            path: 'Disk',
            component: () => import('@/views/isystem/perform/Disk'),
            name: 'Disk',
            meta: { title: '磁盘监控'},
          },
        ]
      }
    ]
  },

  {
    path: '/sysmanage',
    component: Layout,
    redirect: '/sysmanage/user',
    name: 'Sysmanage',
    meta: {
      title: '系统管理',
      icon: 'nested'
    },
    children: [
      {
        path: 'user',
        component: () => import('@/views/sysmanage/user'),
        name: 'User',
        meta: { title: '用户管理' },
      },
      {
        path: 'role',
        component: () => import('@/views/sysmanage/role'),
        name: 'Role',
        meta: { title: '角色管理' },
      },
      {
        path: 'roleUserList',
        component: () => import('@/views/sysmanage/roleUserList'),
        name: 'RoleUserList',
        meta: { title: '角色用户' },
      },
      {
        path: 'depart',
        component: () => import('@/views/sysmanage/depart'),
        name: 'Depart',
        meta: { title: '部门管理' },
      },
      {
        path: 'position',
        component: () => import('@/views/sysmanage/position'),
        name: 'Position',
        meta: { title: '职务管理' },
      },
      {
        path: 'addressList',
        component: () => import('@/views/sysmanage/addressList'),
        name: 'AddressList',
        meta: { title: '通讯录'}
      },
      {
        path: 'permission',
        component: () => import('@/views/sysmanage/permission'),
        name: 'Permission',
        meta: { title: '菜单管理'}
      },
      {
        path: 'dict',
        component: () => import('@/views/sysmanage/dict'),
        name: 'Dict',
        meta: { title: '数据字典'}
      },
    ]
  },

  // 404 page must be placed at the end !!!
  { path: '*', redirect: '/404', hidden: true }
]

const createRouter = () => new Router({
  // mode: 'history', // require service support
  scrollBehavior: () => ({ y: 0 }),
  routes: constantRoutes
})

const router = createRouter()

// Detail see: https://github.com/vuejs/vue-router/issues/1234#issuecomment-357941465
export function resetRouter() {
  const newRouter = createRouter()
  router.matcher = newRouter.matcher // reset router
}

export default router

